package com.utils
{
	import flash.display.Stage;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class Debug
	{
		/**直接输出到屏幕上*/		
		public static const DEBUG:int = 1;
		/**打印到日志文件*/
		public static const LOG:int = 2;
		
		private static var _tf:TextField;
		private var _stage:Stage;
		private static var _debug:Boolean = true;
		/**
		 *输出错误信息 
		 * @param info 错误描述
		 * @param type 
		 * 
		 */		
		public static function echo(info:String,type:int = DEBUG):void
		{
			if(!_debug)			
				return ;
			
			switch(type)
			{
				case DEBUG:
					_tf.appendText(info + "\n");
					_tf.width = _tf.textWidth + 10;
					_tf.height += _tf.textHeight + 10;
					break;	
				case LOG:
					break;	
				default:
					break;
			}
		}
		
		
		public function Debug(stage:Stage)
		{
			_stage = stage;

			createText();
		}
		
		
		/**
		 *创建输出的textfield 
		 * 
		 */		
		private function createText():void
		{
			_tf = new TextField();
			_tf.defaultTextFormat = new TextFormat(null,25,0xFF0000);
			_tf.multiline = true;//多行
			//_tf.wordWrap = true;//自动换行
			_tf.text = "";
			_tf.x = 50;
			_stage.addChild(_tf);
		}

		public function get debug():Boolean
		{
			return _debug;
		}

		public function set debug(value:Boolean):void
		{
			_debug = value;
		}

	}
}